<?php
namespace Home\Controller;
use Think\Controller;
class ReturnController extends Controller{
	private $KEY="49147D34115D841BF9F8B58160D7E1FF";
	public function paybyer(){
		
		file_get_contents("php://input");
		
// 		$path="http://hjsj.91quyum.com/Home/one.txt";
		$arr['status']=1;
		$orderStatus=$_REQUEST['orderStatus'];
		$order_num=$_REQUEST['prdOrdNo'];
		$num=$_REQUEST['orderAmount']/100;
		$where['order_num']=$order_num;
		$member_id=M('Pay')->where($where)->find()['member_id'];
		$where1['member_id']=$member_id;
		if($orderStatus=='01'){
			$pay=M('Pay')->where($where)->save($arr);
			$money=M('Member')->where($where1)->setInc('rmb',$num);
			echo 'SUCCESS';
		}else{
			echo '';
		}
	}
	
	public function paybybank(){
		header('Content-Type:text/plain;charset=utf-8');
		$security_key = 'F5CF87D180E0B9D773C70AD2D0E513F5';
		
		$p1 = file_get_contents("php://input");
		//file_put_contents('log.txt', '签名正确');die;
		$urlarr= parse_url($p1);
		file_put_contents('1.txt',$urlarr);
		$a=file_get_contents('1.txt');
		//$a='partnerCode=PT1327&encryptData=eyJyZXNwQ29kZSI6IjAwIiwib3JkZXJObyI6IjE1MDY0ODQ0NTUiLCJyZXNwRGVzYyI6IuaUr+S7mOaIkOWKnyIsInRyYW54U04iOiIyMDE3MDkyNzAxNzg4NTc4MTgiLCJ0cmFuc0FtdCI6IjIuMiJ9&signData=8E3A5215C2BBC7DF8EFE3B04C22A963C';
		$result1=explode('&', $a);
		$result2=base64_decode(substr($result1[1],11));
		//parse_str($urlarr['path'],$parr);
		//$jsonData = iconv('gbk', 'utf-8', base64_decode($parr['encryptData']));
		//$jsonArr = json_decode(result2,true);
		$result3=json_decode($result2);
		$arr = $this->object2array($result3);
		$arr1['status']=1;
		$order_num=$arr['orderNo'];
		$num=$arr['transAmt'];
		$where['order_num']=$order_num;
		$order=M('Pay')->where($where)->find();
		if($order['status']!=1){
		$where1['member_id']=$order['member_id'];
		ini_set('date.timezone','Asia/Shanghai');
		//file_put_contents('log.txt',$order_num);
			if ($arr['respCode'] == '00') {
				$pay=M('Pay')->where($where)->save($arr1);
				$money=M('Member')->where($where1)->setInc('rmb',$num);
				file_put_contents('log.txt','支付成功');
				//$str='SUCCESS';	
				echo 'SUCCESS';
		}
		else
			echo 'FAIL';
		}
	}
	public function object2array($object) {
		if (is_object($object)) {
			foreach ($object as $key => $value) {
				$array[$key] = $value;
			}
		}
		else {
			$array = $object;
		}
		return $array;
	}
	public function sign($jsonData, $security_key) {
		ini_set('date.timezone','Asia/Shanghai');
		return  md5 ( $jsonData .  $security_key );
	}
	
}
